import { Graph } from '@antv/x6'
import { defaultPort } from '../../../shapes/config'
import { DataType } from '../../../shapes/type'

Graph.registerNode('VariableValue', {
  inherit: 'TextBox',
  text: '变量值',
  ports: defaultPort,
  data: {
    attrRoot: 'body',
    dataConfig: {
      runModel: 'variableValue',
      deviceId: null,
      variableId: null,
      variableAddress: null,
      isShowUnit: false,
      updateData (cell, data: any) {
        let value = data.value || '/'
        if (cell.data.dataConfig.isShowUnit) value += data.unit
        cell.attr('label/text', value)
      }
    },
    events: {
      // added (graph, { cell }) {
      //   console.log(graph, cell)
      // }

    },
    getAttrModules: () => {
      return [
        {
          title: '基本样式',
          group: 'Attrs',
          components: () => import('../../components/NodeBasicAttrs.vue'),
          solution: {}
        },
        {
          title: '文本样式',
          group: 'Attrs',
          components: () => import('../basic/components/TextStyle.vue'),
          solution: {}
        },
        {
          title: '绑定设备变量',
          group: 'Data',
          components: () => import('../../components/BindDeviceVariable.vue'),
          solution: {
          }
        },
        {
          title: '更多',
          group: 'Data',
          components: () => import('./components/More.vue'),
          solution: {}
        }
      ]
    }
  } as DataType
} as any)
